<?php
class CommentController extends Epic_Controller_Action 
{	
	/**
	 * Authentication
	 *
	 * @see Epic_Controller_Action::init()
	 * @return void;
	 */
	public function init()
	{
		if (!Epic::getSession()->get('access')) {
			Epic::setError('You need login to post comment');
			$this->_redirect(Epic::getUrl('blog/article/view', array('id' => $this->getRequest()->getPost('article_id'))));
		}
	}
	
  	public function saveAction() 
  	{
  		if ($data = $this->getRequest()->getPost()) {
  			try {  		
  				// save data
  				Epic::getModel('blog/comment')->save($data);
  		
  				Epic::setFormData(false); // reset form data
  				Epic::setSuccess('The comment has been posted.');
  			} catch (Exception $e) {
  				Epic::setError($e->getMessage());
  			}
  		} else {
  			Epic::setError('Unable to find comment to posted');
  		}
  		$this->_redirect(Epic::getUrl('blog/article/view', array('id' => $data['article_id'])));
  	}
}